import { _decorator, Component, input, Node, Input, EventTouch } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('CameraController')
export class CameraController extends Component {
    start() {
        input.on(Input.EventType.TOUCH_START, this.onTouchStart, this);
        input.on(Input.EventType.TOUCH_END, this.onTouchEnd, this);
        input.on(Input.EventType.TOUCH_MOVE, this.onTouchMove, this);
    }

    onDestroy(){
        input.off(Input.EventType.TOUCH_START, this.onTouchStart, this);
        input.off(Input.EventType.TOUCH_END, this.onTouchEnd, this);
        input.off(Input.EventType.TOUCH_MOVE, this.onTouchMove, this);
    }

    update(deltaTime: number) {
        
    }

    onTouchStart(event: EventTouch) {
        console.log(event.getLocation());
    }
    onTouchEnd(event: EventTouch){
        console.log("Touch Ended", event.getLocation);
    }
    onTouchMove(event: EventTouch){
        console.log("Touch Moved", event.getLocation());
        console.log("Touch Deltat", event.getDelta());

        const scale = 0.1;
        const pos = this.node.position;
        let newPos = pos.clone();
        newPos.x += event.getDelta().x * scale;
        newPos.y += event.getDelta().y * scale;
        this.node.setPosition(newPos);
    }
}


